package server

import (
	"twokick/internal/http/service"
	"github.com/gin-gonic/gin"
	log "github.com/sirupsen/logrus"
	"net/http"
)
var (
	svc  *service.Service
)
func New(s *service.Service) *gin.Engine {
	svc =  s
	ginEngine := gin.Default()
	router(ginEngine)
	return ginEngine
}
func router(e *gin.Engine) {
	// Ping
	e.GET("ping",ping)
	user := e.Group("user")
	{
		user.GET("hello", func(c *gin.Context) {
			result(c,200,nil,"success")
			return
		})

	}
}
func ping(ctx *gin.Context){
	if err := svc.Ping(ctx); err != nil {
		log.Error("Ping error:",err)
		ctx.AbortWithStatus(http.StatusServiceUnavailable)
	}else {
		resultOk(ctx,"pong")
	}
}
